﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Web.UI.WebControls;
using BLL;
using BLL.RF.ATETest;
using BLL.RF.DebugTest;
using BLL.RF.JointingCheck;
using BLL.RF.Package;
using BLL.RF.PowerTest;
using BLL.RF.Repair;
using BLL.RF.SourceCategory;
using BLL.RF.TestRecord;
using BLL.RF.Warehouse;
using Model;
using Model.RF.Package;
using Model.RF.Warehouse;

/// <summary>
/// 1.此页面不适用于二合一产品按成品序列号检索
/// 2.若二合一产品以腔体序列号检索，则只能检索到包装前的数据（可以检索到包装数据）
/// </summary>
public partial class ViewbyProduct_ViewProductState_ProductSNLifeTime : System.Web.UI.Page
{
    string productSN;
    private PackageProduct pp;
    private ProductSNState ps;
    private ProductSNStateInfo psi;

    public ViewbyProduct_ViewProductState_ProductSNLifeTime()
    {
        pp = new PackageProduct();
        ps = new ProductSNState();
        psi = new ProductSNStateInfo();
    }

    #region 腔体与成品序列号都可以链接到这个页面
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["ProductSN"] != null)
            {
                productSN = Request.QueryString["ProductSN"];
                this.TextBox1.Text = productSN;
                productSN = CommHelper.GetProductSN(productSN);
                BindPage();
            }
        }
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        productSN = this.TextBox1.Text.Trim();
        productSN = CommHelper.GetProductSN(productSN);
        BindPage();
    }
    #endregion

    #region 页面绑定数据
    protected void BindPage()
    {
        BindHouseAndMO();
        BindAssembleDetail();
        BindAssembleStep();
        BindBlotScrew();
        BindPortTest();
        BindJointingCheck();
        BindPCBAUnion();
        BindQCFixedCheck();

        ProductIsDebug();
        ProductIsPIM();
        ProductIsTest();
        ProductIsPackage();
        ImageProcess();

        BindAging();
        BindDebugATETests();
        BindDebugTests();
        BindPIMTests();
        BindPowerTests();
        BindDebugTest_Actives();
        BindVoltageChecks();
        BindCurrentChecks();
        BindSensitivitys();
        BindTests();
        BindTest_Actives();
        BindOIP3s();
        BindHFTests();
        BindAirtightness();
        BindPIMSecondTests();
        BindQCPackCheck();
        BindPackageProduct();
        BindPack_Label_Print();
        BindPackintoBox();
        BindUnpackfromBox();
        BindStockOut();

        BindNFChecks();
        BindEPROMChecks();
        BindVSWRChecks();
        BindFinalChecks();

        BindRepairLock();
        BindRepair();
    }
    #endregion

    #region 流程图逻辑
    public void ProductIsDebug()
    {
        psi = ps.ProductSN_IsDebug(productSN);
        if (psi.IsPass != null)
        {
            if (psi.IsPass == "Pass")
            {
                this.LinkButton1.BackColor = Color.Green;
                this.Label1.Text = psi.TestTime.ToString();
            }
            else
            {
                this.LinkButton1.BackColor = Color.Red;
                this.Label1.Text = psi.TestTime.ToString();
            }
            //this.LinkButton1.Enabled = true;
        }
        else               //当不存在记录时，清空效果与显示
        {
            this.LinkButton1.BackColor = Color.Empty;
            this.Label1.Text = "";
            //this.LinkButton1.Enabled = false;
        }
        this.LinkButton1.Visible = true;
        this.Label1.Visible = true;
    }

    public void ProductIsPIM()
    {
        psi = ps.ProductSN_IsPIM(productSN);
        if (psi.IsPass != null)
        {
            if (psi.IsPass.Equals("Pass", StringComparison.OrdinalIgnoreCase))
            {
                this.LinkButton2.BackColor = Color.Green;
                this.Label2.Text = psi.TestTime.ToString();
            }
            else
            {
                this.LinkButton2.BackColor = Color.Red;
                this.Label2.Text = psi.TestTime.ToString();
            }
            this.LinkButton2.Enabled = true;
        }
        else
        {
            this.LinkButton2.BackColor = Color.Empty;
            this.Label2.Text = "";
            this.LinkButton2.Enabled = false;
        }
        this.LinkButton2.Visible = true;
        this.Label2.Visible = true;
    }

    public void ProductIsTest()
    {
        psi = ps.ProductSN_IsTest(productSN);
        if (psi.IsPass != null)
        {
            if (psi.IsPass.Equals("Pass", StringComparison.OrdinalIgnoreCase))
            {
                this.LinkButton3.BackColor = Color.Green;
                this.Label3.Text = psi.TestTime.ToString();
            }
            else
            {
                this.LinkButton3.BackColor = Color.Red;
                this.Label3.Text = psi.TestTime.ToString();
            }
            this.LinkButton3.Enabled = true;
        }
        else
        {
            this.LinkButton3.BackColor = Color.Empty;
            this.Label3.Text = "";
            this.LinkButton3.Enabled = false;
        }
        this.LinkButton3.Visible = true;
        this.Label3.Visible = true;
    }

    public void ProductIsPackage()
    {
        psi = ps.ProductSN_IsPackage(productSN);
        if (psi.IsPass != null)
        {
            if (psi.IsPass == "Yes")
            {
                this.LinkButton4.BackColor = Color.Green;
                this.Label4.Text = psi.TestTime.ToString();
            }
            else
            {
                this.LinkButton4.BackColor = Color.Red;
                this.Label4.Text = psi.TestTime.ToString();
            }
            this.LinkButton4.Enabled = true;
        }
        else
        {
            this.LinkButton4.BackColor = Color.Empty;
            this.Label4.Text = "";
            this.LinkButton4.Enabled = false;
        }
        this.LinkButton4.Visible = true;
        this.Label4.Visible = true;
    }

    public void ImageProcess()
    {
        if (this.LinkButton1.BackColor == Color.Green && this.LinkButton2.BackColor == Color.Green)
        {
            this.Image1.ImageUrl = "~/Images/ViewbyProduct/GreenArrow.png";
        }
        else
        {
            this.Image1.ImageUrl = "~/Images/ViewbyProduct/GrayArrow.png";
        }
        if (this.LinkButton2.BackColor == Color.Green && this.LinkButton3.BackColor == Color.Green)
        {
            this.Image2.ImageUrl = "~/Images/ViewbyProduct/GreenArrow.png";
        }
        else
        {
            this.Image2.ImageUrl = "~/Images/ViewbyProduct/GrayArrow.png";
        }
        if (this.LinkButton3.BackColor == Color.Green && this.LinkButton4.BackColor == Color.Green)
        {
            this.Image3.ImageUrl = "~/Images/ViewbyProduct/GreenArrow.png";
        }
        else
        {
            this.Image3.ImageUrl = "~/Images/ViewbyProduct/GrayArrow.png";
        }
        this.Image1.Visible = true;
        this.Image2.Visible = true;
        this.Image3.Visible = true;
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Session["productSN"] = this.TextBox1.Text.Trim();
        Session["testTime"] = Convert.ToDateTime(this.Label1.Text);
        Response.Redirect("~/ViewTest/ViewYourself/ViewTestItem.aspx");
    }

    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Session["productSN"] = this.TextBox1.Text.Trim();
        Session["testTime"] = Convert.ToDateTime(this.Label2.Text);
        Response.Redirect("~/ViewTest/ViewYourself/PIMTestItemViewbySNDT.aspx");
    }

    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        Session["productSN"] = this.TextBox1.Text.Trim();
        Session["testTime"] = Convert.ToDateTime(this.Label3.Text);
        Response.Redirect("~/ViewTest/ViewYourself/ViewTestItem.aspx");
    }

    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        Session["productSN"] = this.TextBox1.Text.Trim();
        Response.Redirect("~/ViewbyProduct/ViewProductState/PackagebyProductSN.aspx");
    }
    #endregion

    #region 装配相关
    protected void BindHouseAndMO()
    {
        IList<HouseAndMOInfo> list = new List<HouseAndMOInfo>();
        HouseAndMOInfo hmi = BuildHouseAndMOInfo();
        if (hmi != null)
        {
            list.Add(hmi);
        }
        this.GV_MO.DataSource = list; 
        this.GV_MO.DataBind();
    }

    protected HouseAndMOInfo BuildHouseAndMOInfo()
    {
        MO m = new MO();
        House h = new House();
        string mOID = h.LoadEntity(productSN).MOID;
        if (!string.IsNullOrEmpty(mOID))
        {
            string productTypeID = m.LoadEntity(mOID).ProductTypeID;
            if (!string.IsNullOrEmpty(productTypeID))
            {
                HouseAndMOInfo hmi = new HouseAndMOInfo(productTypeID, mOID, productSN);
                return hmi;
            }
        } 
        return null;
    }

    protected void BindAssembleDetail()
    {
        AssembleDetail ad = new AssembleDetail();
        this.GV_AssembleDetail.DataSource = ad.GetAssembleDetailbySN(productSN);
        this.GV_AssembleDetail.DataBind();
    }

    protected void BindAssembleStep()
    {
        AssembleStep astep = new AssembleStep();
        this.GV_AssembleStep.DataSource = astep.GetAssembleStepbySN(productSN);
        this.GV_AssembleStep.DataBind();
    }

    protected void BindBlotScrew()
    {
        BlotScrew bs = new BlotScrew();
        this.GV_BlotScrew.DataSource = bs.GetBlotScrewsbySN(productSN);
        this.GV_BlotScrew.DataBind();
    }

    protected void BindPortTest()
    {
        PortTest pt = new PortTest();
        this.GV_PortTest.DataSource = pt.PortTest_SelectbySN(productSN);
        this.GV_PortTest.DataBind();
    }

    protected void BindJointingCheck()
    {
        JointingCheck jc = new JointingCheck();
        this.GV_JointingCheck.DataSource = jc.GetJointingChecksbySN(productSN);
        this.GV_JointingCheck.DataBind();
    }

    protected void BindPCBAUnion()
    {
        PCBAUnion pu = new PCBAUnion();
        this.GV_PCBAUnion.DataSource = pu.GetPCBAUnionbySN(productSN);
        this.GV_PCBAUnion.DataBind();
    }

    protected void BindQCFixedCheck()
    {
        QCFixedCheck qcfc = new QCFixedCheck();
        this.GV_QCFixedCheck.DataSource = qcfc.GetQCFixedChecksbySN(productSN);
        this.GV_QCFixedCheck.DataBind();
    }
    #endregion

    #region 测试相关
    protected void BindAging()
    {
        Aging a = new Aging();
        this.GV_Aging.DataSource = a.GetAgingsbySN(productSN);
        this.GV_Aging.DataBind();
    }

    protected void BindDebugATETests()
    {
        Interim test = new Interim();
        GV_DebugATETest.DataSource = test.GetDebugTestsbyProductSN(productSN);
        GV_DebugATETest.DataBind();
        for (int i = 0; i < GV_DebugATETest.Rows.Count; i++)
        {
            if (GV_DebugATETest.Rows[i].Cells[6].Text == "Fail")
                GV_DebugATETest.Rows[i].Cells[6].ForeColor = System.Drawing.Color.Red;
        }
    }

    protected void BindDebugTests()
    {
        DebugTest test = new DebugTest();
        GV_DebugTest.DataSource = test.DebugTest_SelectbySN(productSN);
        GV_DebugTest.DataBind();
    }

    protected void BindPIMTests()
    {
        PIMTest pt = new PIMTest();
        this.GV_PIMTest.DataSource = pt.GetPIMTestbyProductSN(productSN);
        this.GV_PIMTest.DataBind();
        for (int i = 0; i < GV_PIMTest.Rows.Count; i++)
        {
            if (GV_PIMTest.Rows[i].Cells[10].Text == "Fail")
                GV_PIMTest.Rows[i].Cells[10].ForeColor = System.Drawing.Color.Red;
        }
    }

    protected void BindPowerTests()
    {
        PowerTest pt = new PowerTest();
        this.GV_PowerTest.DataSource = pt.GetPowerTestsbySN(productSN);
        this.GV_PowerTest.DataBind();
        for (int i = 0; i < GV_PowerTest.Rows.Count; i++)
        {
            if (GV_PowerTest.Rows[i].Cells[8].Text == "Fail")
                GV_PowerTest.Rows[i].Cells[8].ForeColor = System.Drawing.Color.Red;
        }
    }

    protected void BindDebugTest_Actives()
    {
        Test_Active test = new Test_Active();
        GV_DebugTest_Active.DataSource = test.DebugTest_Active_GetbyProductSN(productSN);
        GV_DebugTest_Active.DataBind();
        for (int i = 0; i < GV_DebugTest_Active.Rows.Count; i++)
        {
            if (GV_DebugTest_Active.Rows[i].Cells[6].Text == "Fail")
                GV_DebugTest_Active.Rows[i].Cells[6].ForeColor = System.Drawing.Color.Red;
        }
    }

    protected void BindVoltageChecks()
    {
        Test_Record t = new Test_Record();
        this.GV_VoltageCheck.DataSource = t.Test_Record_GetVoltageCheck_bySN(productSN);
        this.GV_VoltageCheck.DataBind();
    }

    protected void BindCurrentChecks()
    {
        Test_Record t = new Test_Record();
        this.GV_CurrentCheck.DataSource = t.Test_Record_GetCurrentCheck_bySN(productSN);
        this.GV_CurrentCheck.DataBind();
    }

    protected void BindSensitivitys()
    {
        Test_Record t = new Test_Record();
        this.GV_Sensitivity.DataSource = t.Test_Record_GetSensitivity_bySN(productSN);
        this.GV_Sensitivity.DataBind();
    }

    protected void BindTests()
    {
        Test test = new Test();
        GV_Test.DataSource = test.GetTestsbyProductSN(productSN);
        GV_Test.DataBind();
        for (int i = 0; i < GV_Test.Rows.Count; i++)
        {
            if (GV_Test.Rows[i].Cells[6].Text == "Fail")
                GV_Test.Rows[i].Cells[6].ForeColor = System.Drawing.Color.Red;
        }
    }

    protected void BindTest_Actives()
    {
        Test_Active test = new Test_Active();
        GV_Test_Active.DataSource = test.Test_Active_GetbyProductSN(productSN);
        GV_Test_Active.DataBind();
        for (int i = 0; i < GV_Test_Active.Rows.Count; i++)
        {
            if (GV_Test_Active.Rows[i].Cells[6].Text == "Fail")
                GV_Test_Active.Rows[i].Cells[6].ForeColor = System.Drawing.Color.Red;
        }
    }

    protected void BindOIP3s()
    {
        Test_Record t = new Test_Record();
        this.GV_OIP3.DataSource = t.Test_Record_GetOIP3_bySN(productSN);
        this.GV_OIP3.DataBind();
    }

    protected void BindHFTests()
    {
        Test t = new Test();
        this.GV_HFTest.DataSource = t.GetHgihFTestbySN(productSN);
        this.GV_HFTest.DataBind();
        for (int i = 0; i < GV_HFTest.Rows.Count; i++)
        {
            if (GV_HFTest.Rows[i].Cells[6].Text == "Fail")
                GV_HFTest.Rows[i].Cells[6].ForeColor = System.Drawing.Color.Red;
        }
    }

    protected void BindAirtightness()
    {
        Airtightness ai = new Airtightness();
        this.GV_Airtightness.DataSource = ai.Airtightness_SelectbySN(productSN);
        this.GV_Airtightness.DataBind();
        for (int i = 0; i < this.GV_Airtightness.Rows.Count; i++)
        {
            if (bool.Parse(GV_Airtightness.DataKeys[i].Values[0].ToString()))
            {
                this.GV_Airtightness.Rows[i].Cells[6].Text = "Pass";
            }
            else
            {
                this.GV_Airtightness.Rows[i].Cells[6].Text = "Fail";
                this.GV_Airtightness.Rows[i].Cells[6].ForeColor = System.Drawing.Color.Red;
            }
        }
    }

    protected void BindPIMSecondTests()
    {
        PIMTest pt = new PIMTest();
        this.GV_PIMSecondTest.DataSource = pt.GetPIMSecondTestbyProductSN(productSN);
        this.GV_PIMSecondTest.DataBind();
        for (int i = 0; i < GV_PIMSecondTest.Rows.Count; i++)
        {
            if (GV_PIMSecondTest.Rows[i].Cells[10].Text == "Fail")
                GV_PIMSecondTest.Rows[i].Cells[10].ForeColor = System.Drawing.Color.Red;
        }
    }

    protected void BindQCPackCheck()
    {
        QCPackCheck qcpc = new QCPackCheck();
        this.GV_QCPackCheck.DataSource = qcpc.GetQCPackChecksbySN(productSN);
        this.GV_QCPackCheck.DataBind();
    }

    private void BindPackageProduct()
    {
        PackageProduct test = new PackageProduct();
        IList<PackageProductInfo> ppis = new List<PackageProductInfo>();
        PackageProductInfo ppi = test.GetAllPackagebyProductSN(productSN);
        if (ppi != null)
            ppis.Add(ppi);

        Package p = new Package();
        SNUnion u = new SNUnion();
        SNUnionInfo ui = u.LoadEntity(productSN);
        if (!string.IsNullOrEmpty(ui.PackageProductSN))
        {
            PackageInfo pi= p.LoadEntity(ui.PackageProductSN);
            if (!string.IsNullOrEmpty(pi.PackageProductSN))
            {
                PackageProductInfo ppinfo = new PackageProductInfo() 
                { 
                    PackageProductSN=pi.PackageProductSN,
                    ProductSN=ui.ProductSN,
                    ProductTypeID=ui.ProductTypeID,
                    UnionTime=ui.RecordTime,
                    UserID=ui.UserID,
                    PackageTime=pi.RecordTime,
                    Packer=pi.UserID,
                    IsPackage="Yes",
                };
                ppis.Add(ppinfo);
            }
        }

        this.GV_PackageProduct.DataSource = ppis;
        this.GV_PackageProduct.DataBind();
    }

    private void BindPack_Label_Print()
    {
        Pack_Label_Print plp = new Pack_Label_Print();
        PackageProductInfo ppi = pp.GetAllPackagebyProductSN(productSN);
        if (ppi != null)
        {
            this.GV_Pack_Label_Print.DataSource = plp.GetPack_Label_Prints_byPackageProductSN(ppi.PackageProductSN);
            this.GV_Pack_Label_Print.DataBind();
        }
        else
        {
            this.GV_Pack_Label_Print.DataSource = null;
            this.GV_Pack_Label_Print.DataBind();
        }
    }

    private void BindPackintoBox()
    {
        PackintoBoxItem pbi = new PackintoBoxItem();
        PackageProductInfo ppi = pp.GetAllPackagebyProductSN(productSN);
        if (ppi != null)
        {
            this.GV_PackintoBox.DataSource = pbi.GetPackintoBoxItem_bySN(ppi.PackageProductSN);
            this.GV_PackintoBox.DataBind();
        }
        else
        {
            this.GV_PackintoBox.DataSource = null;
            this.GV_PackintoBox.DataBind();
        }
    }

    public void BindUnpackfromBox()
    {
        UnpackfromBoxItem ubi = new UnpackfromBoxItem();
        PackageProductInfo ppi = pp.GetAllPackagebyProductSN(productSN);
        if (ppi != null)
        {
            this.GV_UnpackfromBox.DataSource = ubi.GetUnpackfromBoxItem_bySN(ppi.PackageProductSN);
            this.GV_UnpackfromBox.DataBind();
        }
        else
        {
            this.GV_UnpackfromBox.DataSource = null;
            this.GV_UnpackfromBox.DataBind();
        }
    }

    private void BindStockOut()
    {
        StockOut so = new StockOut();
        IList<StockOutInfo> sois = new List<StockOutInfo>();
        PackageProductInfo ppi = pp.GetAllPackagebyProductSN(productSN);
        if (ppi != null)
        {
            string ppsn = ppi.PackageProductSN;
            //if (!string.IsNullOrEmpty(ppsn))
            {
                StockOutInfo soi = so.LoadEntity(ppsn);
                if (soi != null)
                    sois.Add(soi);
            }
        }
        this.GV_StockOut.DataSource = sois;
        this.GV_StockOut.DataBind();
    }

    protected void BindNFChecks()
    {
        NFCheck nc = new NFCheck();
        this.GV_NFCheck.DataSource = nc.NFCheck_GetbySN(productSN);
        this.GV_NFCheck.DataBind();
    }

    protected void BindEPROMChecks()
    {
        EPROMCheck ec = new EPROMCheck();
        this.GV_EPROMCheck.DataSource = ec.GetEPROMCheckbySN(productSN);
        this.GV_EPROMCheck.DataBind();
    }

    protected void BindVSWRChecks()
    {
        VSWRCheck vc = new VSWRCheck();
        this.GV_VSWRCheck.DataSource = vc.GetVSWRCheckbySN(productSN);
        this.GV_VSWRCheck.DataBind();
    }

    protected void BindFinalChecks()
    {
        FinalCheck fc = new FinalCheck();
        this.GV_FinalCheck.DataSource = fc.GetFinalCheckbySN(productSN);
        this.GV_FinalCheck.DataBind();
    }
    #endregion

    #region 返修相关
    protected void BindRepairLock()
    {
        RepairLock rl = new RepairLock();
        this.GV_RepairLock.DataSource = rl.RepairLock_GetbyProductSN(productSN);
        this.GV_RepairLock.DataBind();
    }

    protected void BindRepair()
    {
        Repair rep = new Repair();
        this.GV_Repair.DataSource = rep.GetRepairbySN(productSN);
        this.GV_Repair.DataBind();
    }
    #endregion

    #region 测试数据详细，用session传值过去
    protected void GV_PowerTest_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["ID"] = Convert.ToInt32(GV_PowerTest.SelectedDataKey["ID"]);
        Response.Redirect("~/ViewTest/ViewYourself/PowerTestItemViewbyID.aspx");
    }

    protected void GV_PIMTest_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["productSN"] = GV_PIMTest.SelectedDataKey["ProductSN"].ToString();
        Session["testTime"] = Convert.ToDateTime(GV_PIMTest.SelectedDataKey["TestTime"]);

        Response.Redirect("~/ViewTest/ViewYourself/PIMTestItemViewbySNDT.aspx");
    }

    protected void GV_PIMSecondTest_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["productSN"] = GV_PIMSecondTest.SelectedDataKey["ProductSN"].ToString();
        Session["testTime"] = Convert.ToDateTime(GV_PIMSecondTest.SelectedDataKey["TestTime"]);

        Response.Redirect("~/ViewTest/ViewYourself/PIMSecondTestItemViewbySNDT.aspx");
    }

    protected void GV_Test_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["productSN"] = GV_Test.SelectedDataKey["ProductSN"].ToString();
        Session["testTime"] = Convert.ToDateTime(GV_Test.SelectedDataKey["TestTime"]);
        Session["ProductTypeID"] = GV_Test.SelectedDataKey["ProductTypeID"].ToString();
        Session["UserID"] = GV_Test.SelectedDataKey["UserID"].ToString();
        Session["ENAID"] = GV_Test.SelectedDataKey["ENAID"].ToString();
        Session["SpecVersion"] = GV_Test.SelectedDataKey["SpecVersion"].ToString();
        Session["IsPass"] = GV_Test.SelectedDataKey["IsPass"].ToString();

        Response.Redirect("~/ViewTest/ViewYourself/ViewTestItem.aspx");
    }

    protected void GV_Test_Active_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["productSN"] = GV_Test_Active.SelectedDataKey["ProductSN"].ToString();
        Session["testTime"] = Convert.ToDateTime(GV_Test_Active.SelectedDataKey["TestTime"]);
        Session["ProductTypeID"] = GV_Test_Active.SelectedDataKey["ProductTypeID"].ToString();
        Session["UserID"] = GV_Test_Active.SelectedDataKey["UserID"].ToString();
        Session["ENAID"] = GV_Test_Active.SelectedDataKey["ENAID"].ToString();
        Session["SpecVersion"] = GV_Test_Active.SelectedDataKey["SpecVersion"].ToString();
        Session["IsPass"] = GV_Test_Active.SelectedDataKey["IsPass"].ToString();

        Response.Redirect("~/ViewTest/ViewYourself/ViewTestItem_Active.aspx");
    }

    protected void GV_HFTest_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["productSN"] = GV_HFTest.SelectedDataKey["ProductSN"].ToString();
        Session["testTime"] = Convert.ToDateTime(GV_HFTest.SelectedDataKey["TestTime"]);
        Session["ProductTypeID"] = GV_HFTest.SelectedDataKey["ProductTypeID"].ToString();
        Session["UserID"] = GV_HFTest.SelectedDataKey["UserID"].ToString();
        Session["ENAID"] = GV_HFTest.SelectedDataKey["ENAID"].ToString();
        Session["IsPass"] = GV_HFTest.SelectedDataKey["IsPass"].ToString();

        Response.Redirect("~/ViewTest/ViewYourself/ViewHFTestItem.aspx");
    }

    protected void GV_DebugATETest_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["productSN"] = GV_DebugATETest.SelectedDataKey["ProductSN"].ToString();
        Session["testTime"] = Convert.ToDateTime(GV_DebugATETest.SelectedDataKey["TestTime"]);
        Session["ProductTypeID"] = GV_DebugATETest.SelectedDataKey["ProductTypeID"].ToString();
        Session["UserID"] = GV_DebugATETest.SelectedDataKey["UserID"].ToString();
        Session["ENAID"] = GV_DebugATETest.SelectedDataKey["ENAID"].ToString();
        Session["SpecVersion"] = GV_DebugATETest.SelectedDataKey["SpecVersion"].ToString();
        Session["IsPass"] = GV_DebugATETest.SelectedDataKey["IsPass"].ToString();

        Response.Redirect("~/ViewTest/ViewYourself/ViewTestItem.aspx");
    }

    protected void GV_DebugTest_Active_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["productSN"] = GV_DebugTest_Active.SelectedDataKey["ProductSN"].ToString();
        Session["testTime"] = Convert.ToDateTime(GV_DebugTest_Active.SelectedDataKey["TestTime"]);
        Session["ProductTypeID"] = GV_DebugTest_Active.SelectedDataKey["ProductTypeID"].ToString();
        Session["UserID"] = GV_DebugTest_Active.SelectedDataKey["UserID"].ToString();
        Session["ENAID"] = GV_DebugTest_Active.SelectedDataKey["ENAID"].ToString();
        Session["SpecVersion"] = GV_DebugTest_Active.SelectedDataKey["SpecVersion"].ToString();
        Session["IsPass"] = GV_DebugTest_Active.SelectedDataKey["IsPass"].ToString();

        Response.Redirect("~/ViewTest/ViewYourself/ViewTestItem_Active.aspx");
    }
    #endregion

    #region 测试数据结果着色区分
    protected void GV_NFCheck_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if ((bool)GV_NFCheck.DataKeys[e.Row.RowIndex].Values[3] == true)
            {
                e.Row.Cells[5].Text = "Pass";
            }
            else
            {
                e.Row.Cells[5].Text = "Fail";
                e.Row.Cells[5].ForeColor = System.Drawing.Color.Red;
            }
        }
    }

    protected void GV_VSWRCheck_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //if (e.Row.Cells[5].Text == "True")
            if ((bool)GV_VSWRCheck.DataKeys[e.Row.RowIndex].Values[2] == true)
            {
                e.Row.Cells[4].Text = "Pass";
            }
            else
            {
                e.Row.Cells[4].Text = "Fail";
                e.Row.Cells[4].ForeColor = System.Drawing.Color.Red;
            }
        }
    }

    protected void GV_EPROMCheck_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //if (e.Row.Cells[6].Text == "True")
            if ((bool)GV_EPROMCheck.DataKeys[e.Row.RowIndex].Values[2] == true)
            {
                e.Row.Cells[6].Text = "Pass";
            }
            else
            {
                e.Row.Cells[6].Text = "Fail";
                e.Row.Cells[6].ForeColor = System.Drawing.Color.Red;
            }
        }
    }

    protected void GV_FinalCheck_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //if (e.Row.Cells[5].Text == "True")
            if ((bool)GV_FinalCheck.DataKeys[e.Row.RowIndex].Values[2] == true)
            {
                e.Row.Cells[4].Text = "Pass";
            }
            else
            {
                e.Row.Cells[4].Text = "Fail";
                e.Row.Cells[4].ForeColor = System.Drawing.Color.Red;
            }
        }
    }

    protected void GV_Aging_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[6].Text != "Pass")
            {
                e.Row.Cells[6].Text = "不合格";
                e.Row.Cells[6].ForeColor = System.Drawing.Color.Red;
            }
        }
    }

    protected void GV_VoltageCheck_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if ((bool)GV_VoltageCheck.DataKeys[e.Row.RowIndex].Values[2] == true)
            {
                e.Row.Cells[7].Text = "Pass";
            }
            else
            {
                e.Row.Cells[7].Text = "Fail";
                e.Row.Cells[7].ForeColor = System.Drawing.Color.Red;
            }
        }
    }

    protected void GV_CurrentCheck_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if ((bool)GV_CurrentCheck.DataKeys[e.Row.RowIndex].Values[2] == true)
            {
                e.Row.Cells[7].Text = "Pass";
            }
            else
            {
                e.Row.Cells[7].Text = "Fail";
                e.Row.Cells[7].ForeColor = System.Drawing.Color.Red;
            }
        }
    }

    protected void GV_Sensitivity_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if ((bool)GV_Sensitivity.DataKeys[e.Row.RowIndex].Values[2] == true)
            {
                e.Row.Cells[7].Text = "Pass";
            }
            else
            {
                e.Row.Cells[7].Text = "Fail";
                e.Row.Cells[7].ForeColor = System.Drawing.Color.Red;
            }
        }
    }

    protected void GV_OIP3_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if ((bool)GV_OIP3.DataKeys[e.Row.RowIndex].Values[2] == true)
            {
                e.Row.Cells[7].Text = "Pass";
            }
            else
            {
                e.Row.Cells[7].Text = "Fail";
                e.Row.Cells[7].ForeColor = System.Drawing.Color.Red;
            }
        }
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if ((bool)this.GV_RepairLock.DataKeys[e.Row.RowIndex].Values[2] == true)
            {
                e.Row.Cells[3].Text = "已锁定";
            }
            else
            {
                e.Row.Cells[3].Text = "已解锁";
            }
        }
    }
    #endregion
}
